package com.shengdacar.sharelibrary.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import java.util.List;

/**
 * 作者：huyi
 * 日期：2020/12/17 17:18
 * 描述：
 */
public class appUtil {
    /**
     * 判断应用是否安装
     *
     * @param pkName 判断的应用包名
     * @return
     */
    public static boolean isAppAvailable(Context context, String pkName) {
        if (TextUtils.isEmpty(pkName)) {
            return false;
        }
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                if (pn.equals(pkName)) {
                    return true;
                }
            }
        }
        return false;
    }
}
